package br.edu.ufcg.msnlab2.grupo05.Grafico;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Event;
import java.awt.Label;
import java.awt.Panel;
import java.util.ArrayList;

import br.edu.ufcg.msnlab2.misc.Point;




public class SplineGrafico extends Applet {

	private Label lbPoints;

	private Choice chPoints;

	private Checkbox cbLagrange;

	private SplinePanel lagPan;

	private int nPts;

	public SplineGrafico(ArrayList<Point> points) {
		nPts = points.size();
		setLayout(new BorderLayout());
		lbPoints = new Label();
		chPoints = new Choice();
		int i;
		lagPan = new SplinePanel(250, 250, points);
		lagPan.init(nPts, true);
		lagPan.showLagrange(false);
		lagPan.showContributions(false);
		lagPan.showSplines(true);
		add("North", lagPan);
	}

	public boolean handleEvent(Event evt) {
		if (evt.id == Event.ACTION_EVENT) {
			if (evt.target == cbLagrange) {
				lagPan.showLagrange(cbLagrange.getState());
			}
			if (evt.target == chPoints) {
				int n = Integer.parseInt(chPoints.getSelectedItem());
				if (nPts != n) {
					nPts = n;
					lagPan.init(nPts, true);
				}
			}
		}
		return super.handleEvent(evt);
	}
}
